/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "productattributes")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Productattributes.findAll", query = "SELECT p FROM Productattributes p"),
    @NamedQuery(name = "Productattributes.findByProductIdByProviderIdByProductAttributeId", query = "SELECT p FROM Productattributes p WHERE p.productattributesPK.productId = :productId AND p.productattributesPK.providerId = :providerId AND p.productattributesPK.productAttributeId = :productAttributeId"),
    @NamedQuery(name = "Productattributes.findByProductIdByProviderId", query = "SELECT p FROM Productattributes p WHERE p.productattributesPK.productId = :productId AND p.productattributesPK.providerId = :providerId"),
    @NamedQuery(name = "Productattributes.findByProductAttributeId", query = "SELECT p FROM Productattributes p WHERE p.productattributesPK.productAttributeId = :productAttributeId"),
    @NamedQuery(name = "Productattributes.deleteByProviderIdByProductId", query = "DELETE FROM Productattributes p WHERE p.productattributesPK.providerId = :providerId AND p.productattributesPK.productId = :productId"),
    @NamedQuery(name = "Productattributes.findByProviderId", query = "SELECT p FROM Productattributes p WHERE p.productattributesPK.providerId = :providerId"),
    @NamedQuery(name = "Productattributes.findByProductId", query = "SELECT p FROM Productattributes p WHERE p.productattributesPK.productId = :productId")})
public class Productattributes implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductattributesPK productattributesPK;
    
    @JoinColumns({
        @JoinColumn(name = "providerId", referencedColumnName = "providerId", insertable = false, updatable = false),
        @JoinColumn(name = "productId", referencedColumnName = "productId", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Product product;
    @JoinColumn(name = "productAttributeId", referencedColumnName = "productAttributeId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Productattribute productattribute;

    public Productattributes() {
    }

    public Productattributes(ProductattributesPK productattributesPK) {
        this.productattributesPK = productattributesPK;
    }

    public Productattributes(int productAttributeId, int providerId, int productId) {
        this.productattributesPK = new ProductattributesPK(productAttributeId, providerId, productId);
    }

    public Productattributes(Productattribute productattribute,Product product) {
        this.productattributesPK = new ProductattributesPK(productattribute.getProductAttributeId(), product.getProductPK().getProviderId(), product.getProductPK().getProductId());
    }
    
    public ProductattributesPK getProductattributesPK() {
        return productattributesPK;
    }

    public void setProductattributesPK(ProductattributesPK productattributesPK) {
        this.productattributesPK = productattributesPK;
    }


    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Productattribute getProductattribute() {
        return productattribute;
    }

    public void setProductattribute(Productattribute productattribute) {
        this.productattribute = productattribute;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productattributesPK != null ? productattributesPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Productattributes)) {
            return false;
        }
        Productattributes other = (Productattributes) object;
        if ((this.productattributesPK == null && other.productattributesPK != null) || (this.productattributesPK != null && !this.productattributesPK.equals(other.productattributesPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Productattributes[ productattributesPK=" + productattributesPK + " ]";
    }
    
}
